package a2025_03_12;

public class SingleLazy {
    //防止长时间不修改，编译器优化，出现内存可见性问题
    private static volatile SingleLazy singleLazy;

    public static SingleLazy getSingleLazy(){
        if(singleLazy==null){
            //因为后续线程要先加锁，再去判断是否为空，所以为了避免加锁的消耗，在套上一层判断
            synchronized (singleLazy){
                if(singleLazy==null){
                    singleLazy=new SingleLazy();
                }
            }
        }

        return singleLazy;
    }

    private SingleLazy(){}
}
